<template>
  <el-dialog
    title="编辑企业"
    :visible="showDialog"
    @close="handleClose"
    @open="handelOpened"
  >
    <!-- 表单 -->
    <el-form
      ref="addRef"
      label-width="120px"
      :model="editForm"
      :rules="editFormRules"
    >
      <el-form-item label="企业名称" prop="shortName">
        <el-input
          v-model="editForm.shortName"
          style="width: 80%"
          placeholder="请输入企业名称"
        />
      </el-form-item>
      <el-form-item label="所属公司" prop="company">
        <el-input
          v-model="editForm.company"
          style="width: 80%"
          placeholder="请输入所属公司"
        />
      </el-form-item>
      <el-form-item>
        <p>
          <a
            href="https://v.qq.com/x/cover/tz4i07kmn06lbp5/q0025y9bqp3.html?ptag=10524"
            >https://www.tianyancha.com</a
          >
          （在此可查询所属公司全称及简称）
        </p>
      </el-form-item>
      <!-- 城市选择组件 -->
      <city-chose
        :father-city.sync="editForm.province"
        :province.sync="editForm.city"
      />

      <el-form-item label="方向(企业标签)" prop="tags">
        <el-input
          v-model="editForm.tags"
          style="width: 80%"
          placeholder="请选择方向"
        />
      </el-form-item>

      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="editForm.remarks"
          type="textarea"
          style="width: 80%"
          placeholder="内容不能为空"
        />
      </el-form-item>
    </el-form>
    <!-- footer插槽 -->
    <template v-slot:footer>
      <el-button @click.stop="handleClose">取消</el-button>
      <el-button type="primary" @click="handleEdit">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { resetCompanyInfoAPI } from '@/api/company'
export default {
  name: 'EditCompany',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    //   员工信息表单
    editForm: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      editFormRules: {
        must: [
          {
            required: true,
            message: '此信息必须填写',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
    this.handelOpened()
  },
  methods: {
    // 弹窗打开时
    async handelOpened() {},
    // 关闭弹窗
    async handleClose() {
      this.$refs.addRef.validate(async (valid) => {
        if (!valid) return
        this.$emit('update:showDialog', false)
        await this.$refs.addRef.resetFields()
      })
    },
    // 修改
    async handleEdit() {
      try {
        // 整体校验
        // 发起修改请求
        console.log(this.editForm)
        await resetCompanyInfoAPI({ ...this.editForm, isFamous: false })
        // 关闭弹框
        this.handleClose()
        // 获取员工列表
        //   this.$parent.getEmpioyeeList()
        //  推荐子传父
        this.$emit('add-success')
        //   成功提示
        this.$message.success('修改成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::deep .el-dialog {
  width: 800px;
}
</style>
